import { request } from '@/utils/request'
import type {
  User,
  Codetype,
  UserInfo,
  PatientList,
  Patient
} from '@/types/user'
//密码登录
export const loginByPassword = (mobile: string, password: string) =>
  request<User>('/login/password', 'POST', { mobile, password })

//发送验证码
export const sendMobileCode = (mobile: string, type: Codetype) =>
  request('/code', 'GET', { mobile, type })

// 短信登录
export const loginByMobile = (mobile: string, code: string) =>
  request<User>('/login', 'POST', { mobile, code })
//获取用户详情
export const getUserInfo = () => request<UserInfo>('/patient/myUser')
//获取家庭档案
export const getPatientList = () => request<PatientList>('/patient/mylist')
//添加患者
export const addPatient = (patient: Patient) =>
  request('/patient/add', 'POST', patient)
//修改患者
export const editPatient = (patient: Patient) =>
  request('/patient/update', 'PUT', patient)
//删除患者
export const delPatient = (id: string | undefined) =>
  request(`/patient/del/${id}`, 'DELETE')
//查询患者详情
export const getPatientDetail = (id: string) =>
  request<Patient>(`/patient/info/${id}`)

//qq登录
export const loginByQQ = (openId: string) =>
  request<User>('/login/thirdparty', 'POST', { openId, source: 'qq' })

//绑定手机号
export const bindMobile = (data: {
  mobile: string
  code: string
  openId: string
}) => request<User>('/login/binding', 'POST', data)
